# -*- coding: utf-8 -*-
from math import sqrt

def sim_distance(pref,person1,person2):
    si={}
    for item in pref[person1]:
        if item in pref[person2]:
            si[item]=1

    if len(si)==0: return 0

    sum_of_squres = sum([pow(pref[person1][item]-pref[person2][item],2)
               for item in pref[person1] if item in pref[person2]])

    return 1/(1+sqrt(sum_of_squres))

